package cc.vv.btpartyjob.partyservice.delegate

import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.baselibrary.util.ColorUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partyservice.R
import cc.vv.btpartyjob.partyservice.adapter.ResourceAdapter
import cc.vv.btpartyjob.partyservice.module.bean.ResourceBean
import cc.vv.mvp.delegate.BaseAppDelegate
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 资源清单托管类
 * Created by Chen.qi on 2018/10/24.
 */
class ResourceListActivityDelegate : BaseAppDelegate() {

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_resource_list
    }


    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_arlS_topBar)
        titleBar?.setTitle(topBarTitle)
    }


    fun showZuZhiSearch(isShow: Boolean = false) {
        val rightIcon = getView<ImageView>(R.id.iv_arlS_zuZhiSearch)
        if (isShow) {
            rightIcon?.visibility = View.VISIBLE
        } else {
            rightIcon?.visibility = View.GONE
        }
    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_arlS_topBar)
        titleBar?.setEventInterface(event)
    }


    /** 设置适配器*/
    fun setRecyclerViewAdapter(mAdapter: ResourceAdapter?) {
        if (null != mAdapter) {
            val recyclerView = getView<RecyclerView>(R.id.rv_arlS_newsList)
            recyclerView?.layoutManager = LinearLayoutManager(context)
            recyclerView?.adapter = mAdapter
        }
    }


    /** 数据适配器 */
    fun setAdapterData(mAdapter: ResourceAdapter?, list: List<ResourceBean>?) {
        if (null != list) {
            mAdapter?.setNewData(list)
            if (list.isEmpty()) {
                showNoDataView(true)
            } else {
                showNoDataView(false)
            }
        } else {
            showNoDataView(true)
        }
    }

    /**
     * 设置刷新监听
     */
    fun bindRefreshListener(listener: SwipeRefreshLayout.OnRefreshListener) {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_arlS_swipeService)
        refresh?.setOnRefreshListener(listener)
        refresh?.setColorSchemeColors(ColorUtil.setBCColor(R.color.color_FA555C))
    }

    /**
     * 设置刷新停止
     */
    fun stopRefreshing() {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_arlS_swipeService)
        Log.e("lk_chen", "result==" + refresh);
        refresh?.isRefreshing = false
    }

    /**
     * 设置加载更多监听
     */
    fun bindLoadMore(mAdapter: ResourceAdapter?, loadMoreListener: BaseQuickAdapter.RequestLoadMoreListener) {
        val recyclerView = getView<RecyclerView>(R.id.rv_arlS_newsList)
        if (null != recyclerView) {
            mAdapter?.setOnLoadMoreListener(loadMoreListener, recyclerView)
        }
    }

    /** 显示暂无数据缺省页 */
    private fun showNoDataView(isNoData: Boolean) {
        val noData = getView<TextView>(R.id.btv_arlS_comNoData)
        if (isNoData) {
            noData?.visibility = View.VISIBLE
        } else {
            noData?.visibility = View.GONE
        }
    }


    //##############################搜索逻辑#############################//
    /**搜索布局显示*/
    fun showSearchView(isShowSearch: Boolean) {
        val searchTop = getView<RelativeLayout>(R.id.rl_arlS_searchTop)
        if (isShowSearch) {
            searchTop?.visibility = View.VISIBLE
        } else {
            searchTop?.visibility = View.GONE
        }
    }

    /**
     * 搜索布局是否显示
     */
    fun getSearchShow(): Boolean {
        val isShow: Boolean
        val searchTop = getView<RelativeLayout>(R.id.rl_arlS_searchTop)
        isShow = searchTop?.visibility == View.VISIBLE
        return isShow
    }

    /**
     * 获取输入的文本
     */
    fun getInputSearchText(): String {
        val etSearch = getView<TextView>(R.id.et_arlS_inputSearch)
        return etSearch?.text.toString().trim()
    }

    /**
     * 设置起始时间
     */
    fun setStartTime(startTime: String) {
        val tvStartTime = getView<TextView>(R.id.tv_arlS_startTime)
        tvStartTime?.text = startTime
    }

    /**
     * 设置结束时间
     */
    fun setEndTime(startTime: String) {
        val tvEndTime = getView<TextView>(R.id.tv_arlS_endTime)
        tvEndTime?.text = startTime
    }

}